class_name CardSrc
extends Resource

# 卡牌类型
enum Type{
    ATTACK,
    DEFEND,
    POWER
}
# 作用目标
enum Target{
    SELF,
    SINGLE,
    ALL,
    EVERYONE
}

@export_group('卡牌属性')
@export var id:String
@export var type:Type
@export var target:Target
@export var cost:int

@export_group('卡牌视觉')
@export var icon:Texture
@export_multiline var desc:String
@export var sound:AudioStream


func isSingle()->bool:
    return target==Target.SINGLE

# 对于群体效果的卡牌获取目标群体
func getTargets(targets:Array[Node])->Array[Node]:
    if ! targets:return []
    var tree:=targets[0].get_tree()

    match target:
        Target.SELF:
            return tree.get_nodes_in_group('player')
        Target.ALL:
            return tree.get_nodes_in_group('enemies')
        Target.EVERYONE:
            return tree.get_nodes_in_group('player')+tree.get_nodes_in_group('enemies')
        _:return []

# 卡牌打出
func play(targets:Array[Node],playerStats:PlayerStatsSrc)->void:
    Events.cardPlayed.emit(self)
    playerStats.energy-=cost
    if isSingle():applyEffect(targets)
    else:applyEffect(getTargets(targets))

# 卡牌效果-> 虚方法
func applyEffect(_targets:Array[Node])->void:
    pass